package com.wlstock.funi.Trader;

import android.content.Context;

import com.wlstock.funi.constant.SharePrefConstants;
import com.wlstock.funi.dao.MyAccountStockDao;
import com.wlstock.funi.model.MyAccountStocks;
import com.wlstock.funi.utils.SharePreferenceUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 16/9/19.
 */
public class CommonSellConfig extends TraderConfiger implements TraderListener{

    private static CommonSellConfig instance;
    private List<TraderObject> traderObjects;

    private CommonSellConfig(Context mContext) {
        this.mContext = mContext;
    }

    public static CommonSellConfig getInstance(Context mContex) {
        if (instance == null) {
            synchronized (CommonSellConfig.class) {
                if (instance == null) {
                    instance = new CommonSellConfig(mContex);
                }
            }
        }
        return instance;
    }

    @Override
    public Object getTradeTimeParams() {
        return ConfigUtils.trigTime("14:55","14:58");
    }

    @Override
    public Object getTradderTriggerParams() {
        int maxKeepDefaultDays = 5;
        return maxKeepDefaultDays;
    }

    @Override
    public Object getStkCodeParams() {
        return null;
    }

    @Override
    public boolean getIsAutoTrade() {
        return SharePreferenceUtils.getBoolSP(mContext, SharePrefConstants.IS_AUTO_SELL,false);
    }

    @Override
    public Object getTotalMoneyParams() {
        return null;
    }

    @Override
    public boolean isInTradeTime(Object param) {
        if (param instanceof HashMap){
            return ConfigUtils.isTimeInConfigRange((Map<String, String>) param);
        }
        return false;
    }

    @Override
    public boolean tradeTrigger(Object param) {
        int maxKeepDays = 5;
        if (param instanceof Integer){
            maxKeepDays = (int) param;
            List<MyAccountStocks> myStocks = MyAccountStockDao.getInstance(mContext).queryStocksOutOfMaxDays(maxKeepDays);
            traderObjects = new ArrayList<>();
            for (MyAccountStocks stock : myStocks){
                traderObjects.add(new TraderObject(stock));
            }
        }
        return false;
    }

    @Override
    public List<TraderObject> tradeCode(Object param) {
        return traderObjects;
    }


    @Override
    public long tradeTotalMoney(Object param) {
        if (traderObjects!=null && !traderObjects.isEmpty()){
            for (int i = 0 ; i < traderObjects.size(); i++){

            }
        }
        return 0;
    }


    @Override
    public TraderError generateTriggerErrorState() {
        return null;
    }


}
